package com.web.productservice.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class HelloController {

    @SentinelResource(value = "hello",blockHandler = "handleHello",blockHandlerClass = ExceptionHandler.class)
    @RequestMapping("/hello")
    public String hello(){
        return "Hello";
    }

    @RequestMapping("/order")
    @SentinelResource(value = "order",fallback = "orderFallback")
    public String order(){
        Random random = new Random();
        if(random.nextInt(2) == 0){
            throw new RuntimeException("错误");
        }
        return "这是订单";
    }

    public String orderFallback(){
        return "这是降级订单";
    }

    @RequestMapping("/payment")
    public String payment(){
        return "这是支付";
    }


}
